package com.jinkeen.xiaxie.pictureInPicture

import android.content.Context
import android.hardware.display.DisplayManager
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.annotation.RequiresApi
import com.jinkeen.xiaxie.R
import com.jinkeen.xiaxie.base.d
import com.jinkeen.xiaxie.base.log

class TwoScreenActivity : AppCompatActivity() {
    private var secondPresentation: SecondPresentation? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_two_screen)
        showDisplay()
    }

    private fun showDisplay() {
        val displayManager = getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
        val presentationDisplays =
            displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION)
        if (presentationDisplays.isNotEmpty()) {
            //display[0] 主屏
            //display[1] 副屏
            val display = presentationDisplays[0]
            secondPresentation = SecondPresentation(this, display)
            try {
                secondPresentation!!.show()
                d("显示屏幕")
            } catch (e: Exception) {
                e.printStackTrace()
                secondPresentation = null
            }
        }

    }
}